package com.leokok.jts.learning.jts.core.geom;

import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineSegment;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

public class LineSegmentTest {


    /**
     * 线段到点最近的点计算
     */
    @Test
    public void closestPointTest() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry geometry = wktReader.read("LINESTRING (127 24, 212 24)");
        Coordinate[] coordinates = geometry.getCoordinates();

        LineSegment lineSegment = new LineSegment(coordinates[0],coordinates[1]);

        Coordinate p = new Coordinate(166, 9);

        Coordinate coordinateC = lineSegment.closestPoint(p);
        System.out.println(coordinateC);
    }
}
